<?php
require_once 'config/config.php';

$page_index = 5;

$_SESSION["contact"] = array();

if (isset($_POST["etablisssemnt"])) {
    if (md5($_POST["captcha"]) != $_SESSION["valeur_image"]) {
        $_SESSION["contact"] = $_POST;
        header("location:contacts.php?err=1");
        exit();
    } else {
        $etablissement = $_POST["etablisssemnt"];
        $nom = $_POST["nom"];
        $telephone = $_POST["telephone"];
        $email = $_POST["email"];
        $message = $_POST["message"];

        //# Send contact mail
        require_once './lib/swift/swift_required.php';
        $transport = Swift_MailTransport::newInstance();
        $mailer = Swift_Mailer::newInstance($transport);

        $sujet = "Contact - lessentiel-du-sup.com";
        $contenu_mail = '
            <html>
                <head>
                    <title>Invitation au salon Perspectives</title>
                </head>
                <body>
                    <table>
                        <tr><td>Etablissement: </td><td>' . $etablissement . '</td></tr>
                        <tr><td>Nom: </td><td>' . $nom . '</td></tr>
                        <tr><td>Téléphone: </td><td>' . $telephone . '</td></tr>
                        <tr><td>Email: </td><td>' . $email . '</td></tr>
                        <tr><td>Message: </td><td>' . nl2br($message) . '</td></tr>
                    </table>
                </body>
            </html>';
        $contenu_mail = wordwrap($contenu_mail, 70);

        $mail = Swift_Message::newInstance($sujet)
                ->setFrom(array('contact@headway-advisory.com' => 'HEADWAY'))
                ->setTo(array('lessentiel@headway-advisory.com'))
                ->setBody($contenu_mail);
        $mail->setContentType("text/html");
        $mailer->send($mail);
        header("location:contacts.php?msg_sent=1");
        exit();
    }
}

if (isset($_GET["err"]) && ($_GET["err"] == 1))
    $message_erreur = "Saisie captcha  erron&eacute;e. Recommencez.";

if (isset($_GET["msg_sent"]) && ($_GET["msg_sent"] == 1))
    $message_succes = "Votre message a été envoyé avec succès.";
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta NAME="ROBOTS" CONTENT="INDEX,FOLLOW" />
        <meta name="keywords" content="L'essentiel du sup" />
        <meta NAME="DESCRIPTION" CONTENT="L'essentiel du sup" />
        <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" />
        <title>L'essentiel du sup</title>
        <link rel="stylesheet" href="js/validation/css/validationEngine.jquery.css" type="text/css"/>
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <!--[if IE]>
        <link rel="stylesheet" type="text/css" href="css/ie.css" />
        <![endif]-->
        <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
        <script type="text/javascript" src="js/validation/js/languages/jquery.validationEngine-fr.js"></script>
        <script type="text/javascript" src="js/validation/js/jquery.validationEngine.js"></script>

        <script>
            $(function() {
                $("#submit_form").click(function(e) {
                    e.preventDefault();
                    if ($("#form").validationEngine('validate')) {
                        $("#form").submit();
                    }
                    return false;
                });

                $("#reset_form").click(function() {
                    $("#form").validationEngine('hideAll');
                });
            });
        </script>
    </head>
    <body>
        <div class="main">
            <?php include './inc/header.php'; ?>
            <div class="main-content">
                <div class="main-bloc-1">
                    <div class="left-1">
                        <div class="logo-container">
                            <img src="images/logo.png" alt="L'essentiel du sup" />
                        </div>
                    </div>
                    <div class="right-1">
                        <div class="righ-1-content">
                            <div class="bloc-partage">
                                <!-- AddThis Button BEGIN -->
                                <div class="addthis_toolbox addthis_default_style addthis_32x32_style">
                                    <a class="addthis_button_preferred_1"></a>
                                    <a class="addthis_button_preferred_2"></a>
                                    <a class="addthis_button_preferred_3"></a>
                                    <a class="addthis_button_preferred_4"></a>
                                    <a class="addthis_button_compact"></a>
                                    <a class="addthis_counter addthis_bubble_style"></a>
                                </div>
                                <script type="text/javascript">var addthis_config = {"data_track_addressbar": false};</script>
                                <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4fe0e68e70742350"></script>
                                <!-- AddThis Button END -->
                            </div>
                        </div>
                    </div>
                </div>
                <div class="main-bloc-full">
                    <div class="full-bloc-offre" style="margin: 20px auto 0 63px">
                        <div class="bloc-contact-1">
                            <div class="logo-container">
                                <img src="images/logo-headway.png" />
                            </div>
                            <div class="adress">
                                <b>5 Rue de Rochechouart, 75009 Paris</b><br/>
                                <b>Tél. :</b> +33 (0)1.71.19.72.77<br/>
                                <b>Fax :</b> +33 (0)1.41.15.27.36<br/>
                                <b>E-Mail :</b> lessentiel@headway-advisory.com
                            </div>
                        </div>
                        <form id="form" class="form-abonnement" action="" method="POST" style="padding-bottom: 30px; margin-top: 10px;">
                            <div class="form-abonnement-content">
                                <div id="form_beneficiares_container">
                                    <div id="form_beneficiare_uniselect">
                                        <div class="form-row">
                                            <div class="form-title">
                                                Formulaire de contact
                                            </div>
                                        </div>
                                        <?php if (!empty($message_erreur)) { ?>
                                            <p class="msg_error">
                                                <?php echo $message_erreur ?>
                                            </p>
                                        <?php } ?>
                                        <?php if (!empty($message_succes)) { ?>
                                            <p class="msg_success">
                                                <?php echo $message_succes ?>
                                            </p>
                                        <?php } ?>

                                        <div style="width: 350px; float: left">
                                            <div class="form-row">
                                                <label>Etablissement* :</label>
                                                <input style="width: 315px;" type="text" name="etablisssemnt" id="etablisssemnt" class="validate[required]" value="<?php echo $_SESSION["contact"]["etablisssemnt"] ?>" />
                                            </div>
                                            <div class="form-row">
                                                <label>Nom* :</label>
                                                <input style="width: 315px;" type="text" name="nom" id="nom" class="validate[required]" value="<?php echo $_SESSION["contact"]["nom"] ?>" />
                                            </div>
                                            <div class="form-row">
                                                <table>
                                                    <tr>
                                                        <td>
                                                            <label>Téléphone* :</label>
                                                            <input style="width: 120px;" type="text" name="telephone" id="telephone" class="validate[required]" value="<?php echo $_SESSION["contact"]["telephone"] ?>" />
                                                        </td>
                                                        <td>
                                                            <div style="margin-left: 16px;">
                                                                <label>E-mail* :</label>
                                                                <input style="width: 170px;" type="text" name="email" id="email" class="validate[required,custom[email]]" value="<?php echo $_SESSION["contact"]["email"] ?>" />
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                            <div class="form-row">
                                                <table>
                                                    <tr>
                                                        <td>
                                                            <div style="width: 130px;">
                                                                <img id="captche_img" src="lib/captcha/validation.php" alt="Captcha" /> *
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div style="margin-left: 16px;">
                                                                <input style="width: 170px;" type="text" name="captcha" id="captcha" class="validate[required]" />
                                                                <span style="font-size: 11px;">Merci de recopier le code ci-contre</span>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </div>
                                        <div style="float: left;">
                                            <div class="form-row">
                                                <label>Message* :</label>
                                                <textarea style="width: 330px; height: 140px; resize: none; background: none repeat scroll 0 0 #F1F1F2; border: 1px solid #000000" name="message" id="message" class="validate[required]"><?php echo $_SESSION["contact"]["message"] ?></textarea>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                                <div class="form-row" style="margin-top: 15px;">
                                    <button id="submit_form" type="submit" style="margin-left: 78%;">Envoyer</button>
                                    <button id="reset_form" type="reset" style="margin-left: 10px;">Annuler</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <?php include './inc/footer.php'; ?>
        </div>
    </body>
</html>